﻿using System;
using System.Collections.Generic;
using System.Text;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Clientes.Communication.Bovespa.Parametro.ParametroBolsa;

namespace Sinacor.UI.Bovespa.Clientes.Communication
{
    public class ParametroBolsa : BaseCommunication
    {
        #region Campos

        private Communication.Translator.DataContractToModel.ParametroBolsa _translatorDataContractToModel;

        #endregion

        #region Construtor

        /// <summary>
        /// Construtor padrão
        /// </summary>
        /// <param name="session"></param>
        public ParametroBolsa(SessionInformation session)
            : base(session)
        {
            this._translatorDataContractToModel = new Sinacor.UI.Bovespa.Clientes.Communication.Translator.DataContractToModel.ParametroBolsa();
        }

        #endregion

        #region Metodos

        public Model.ParametroBolsa ObterParametroBolsa()
        {
            IParametroBolsa servico = null;

            Model.ParametroBolsa retorno = null;

            try
            {
                using (ServiceInstance<IParametroBolsa> service = new ServiceInstance<IParametroBolsa>())
                {
                    servico = service.TryGetInstance(this.Session);
                    retorno = _translatorDataContractToModel.ToParametroBolsa(servico.ObterParametroBolsa());
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return retorno;
        }

        #endregion
    }
}
